<template>
  <div>
    <t-popup
      v-model="visible"
      placement="center"
      style="width: 90vw"
      @close="showPopuphidee()"
    >
      <div class="popup-content">
        <div class="proptitle">{{ titles }}{{ endtext || "新增" }}</div>
        <div class="form-content">
          <t-form
            :inline="inline"
            :data="formData"
            ref="rulesForm"
            label-position="right"
          >
            <t-form-item label-width="170" v-if="zxs">
              <div style="width: 100%">
                <t-cell-group>
                  <t-cell
                    title="上课时间段："
                    :note="formData.hetimeall || '请选择上课时间'"
                    arrow
                    @click="popupShow('hetimeall')"
                  >
                    <template #note>
                      <span :class="formData.hetimeall&&formData.hetimeall.length ? 't_cell' : ''" >{{
                        formData.hetimeall&&formData.hetimeall.length ?`${formData.hetimeall[0]+'至'+formData.hetimeall[1]}`:'请选择上课时间'
                      }}</span>
                    </template>
                  </t-cell>
                </t-cell-group>
              </div>
              <!-- format="YYYY-MM-DD" -->
              <t-calendar
                v-model:visible="visibleObjs.hetimeall"
                 :value="formData.hetimeall"
                type="range"
                @confirm="handleConfirm('hetimeall', $event)" 
                switchMode="month"
                :minDate="2023"
                 @close="closees('hetimeall', $event)"
              ></t-calendar>
            </t-form-item> 

            <t-form-item label-width="170" v-if="!zxs">
              <div style="width: 100%">
                <t-cell-group>
                  <t-cell
                    title="核校时间："
                    :note="formData.hetimeall || '请选择核校时间'"
                    arrow
                    @click="popupShow('hetimeall')"
                  >
                    <template #note>
                      <span :class="formData.hetimeall&&formData.hetimeall.length ? 't_cell' : ''" >{{
                        formData.hetimeall&&formData.hetimeall.length ?`${formData.hetimeall[0]+'至'+formData.hetimeall[1]}`:'请选择核校时间'
                      }}</span>
                    </template>
                  </t-cell>
                </t-cell-group>
              </div>
              <!-- format="YYYY-MM-DD" -->
              <t-calendar
                v-model:visible="visibleObjs.hetimeall"
                 :value="formData.hetimeall"
                type="range"
                @confirm="handleConfirm('hetimeall', $event)" 
                switchMode="month"
                 @close="closees('hetimeall', $event)"
                :minDate="2023"
              ></t-calendar>
            </t-form-item> 
            <t-form-item label-width="170" v-if="!zxs">
              <div style="width: 100%">
                <t-cell-group>
                  <t-cell
                    title="入校时间："
                    :note="formData.admission_timeall || '请选择入校时间'"
                    arrow
                    @click="popupShow('admission_timeall')"
                  >
                    <template #note>
                      <span :class="formData.admission_timeall&&formData.admission_timeall.length ? 't_cell' : ''" >{{
                        formData.admission_timeall&&formData.admission_timeall.length ?`${formData.admission_timeall[0]+'至'+formData.admission_timeall[1]}`:'请选择入校时间'
                      }}</span>
                    </template>
                  </t-cell>
                </t-cell-group>
              </div>
              <!-- format="YYYY-MM-DD" -->
              <t-calendar
                v-model:visible="visibleObjs.admission_timeall"
                 :value="formData.admission_timeall"
                type="range"
                @close="closees('admission_timeall', $event)"
                @confirm="handleConfirm('admission_timeall', $event)" 
                switchMode="month"
                :minDate="2023"
              ></t-calendar>
            </t-form-item>  
          </t-form>
        </div>
        <div
          class="t-form__footer"
          style="
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-top: 10px;
          "
        >
          <t-button
            size="large"
            theme="primary"
            variant="text"
            @click="showPopuphidee()"
            >关闭</t-button
          >
          <!-- <el-button type="success" @click="showPopup = false" plain>关闭</el-button> -->
           <!-- @click="reset" -->
            
          <div style="display: flex">
            <div>
              <t-button theme="primary" @click="reset" variant="outline" style="margin: 0 10px" 
              >重置</t-button
            >
            <t-button
              style="margin: 0 10px"
              theme="primary"
              :disabled="loading"
              @click="submitForm()"
            >
              {{ endtext || "新增" }}
            </t-button>
            </div>
          
            <!-- <el-button type="success"  @click="submitForm()">{{ endtext || "新增" }}</el-button> -->
          </div>
        </div>
         
      </div>
    </t-popup>
  </div>
</template>
    <script>
import { getStorage } from "@/utils/util";
import dayjs from "dayjs";
export default {
  props: {
    titles: {
      typeof: String,
      default: "超管",
    },
    zxs:{
      typeof:Boolean,
      default:false
    }
  },
  data() {
    return {
       
      visible: false,
      visibleObjs: {},
      passwordSwitch: false,
      endtext: "",
      formData: {},
      rules: {
        region_name: [
          { required: true, message: "请输入地区名称", trigger: "blur" },
        ],
        username: [
          { required: true, message: "请输入账户名称", trigger: "blur" },
        ],
        password: [{ required: true, message: "请输入密码", trigger: "blur" }],
        passwordEdit: [
          { required: true, message: "请输入密码", trigger: "blur" },
        ],
        group_name: [
          { required: true, message: "请选择权限", trigger: "blur" },
        ],
        mobile: [{ required: true, message: "请输入手机号", trigger: "blur" }],
      },
    };
  },
  mounted() {
    this.userInfo = Number(JSON.parse(getStorage("groupId"))); //权限
  },
  methods: {
    reset(){
      let vm=this;
      this.formData={};
      vm.$emit("endlists", this.formData);
      vm.showPopuphidee();
    },
    handleConfirm(value, e) { 
      this.formData[value] = [dayjs(e[0]).format("YYYY-MM-DD"),dayjs(e[1]).format("YYYY-MM-DD")];
    },
    // 遮罩显示点击
    popupShow(value) {
      this.visibleObjs = {};
      console.log(value, "---------value");
      this.visibleObjs[value] = true;
      if(!this.formData[value]){
        this.formData[value]=[];
      }
      
    },
    closees(value, e){
      if(this.formData[value]&&this.formData[value].length===0) delete this.formData[value];
      
    },
    showPopuphidee() {
      // 关闭弹窗
      // this.formData = {};
      this.visible = false;
      this.passwordSwitch = false;
    },
    showends(row, text) {
      this.visible = true;
      console.log(row, "-----row");
      if (text) this.endtext = text;
      if (row) this.formData = { ...row };
    },
    authority(groupArr = [0]) {
      // 权限筛选
      let userInfo = this.userInfo;
      // 当前权限和传来的权限组进行对比
      if (groupArr.some((item) => Number(item) === userInfo)) return true;
      return false;
    },
    submitForm() {
      let vm = this;
      vm.$refs["rulesForm"].validate().then((valid) => {
        if (valid === true) {
          vm.$emit("endlists", this.formData);
          vm.showPopuphidee();

          console.log(valid, "新增成功2");
        }
      });
    },
  },
};
</script>
    
     
    <style scoped>
.popup-content {
  padding: 16px;
  background: #fff;
  border-radius: 12px;
  width: 90vw;
  max-width: 500px;
  box-sizing: border-box;
}

.popup-actions {
  display: flex;
  gap: 12px;
  margin-top: 24px;
}

.empty-tips {
  padding: 8px 0;
  color: var(--td-gray-color-6);
  text-align: center;
}

@media (max-width: 640px) {
  .popup-content {
    width: 100%;
    overflow-y: auto;
  }

  :deep(.t-form-item__label) {
    font-size: 14px;
  }

  :deep(.t-picker__toolbar) {
    padding: 8px 12px;
  }
}
</style>
        
        <style lang="scss" scoped>
.custom-input {
  :deep(.t-t-input--default) {
    font-size: 20px; /* 调整输入框 placeholder 字体大小 */
  }
}
</style>
        
        <style>
.t-form__label--right {
  font-size: 14px;
}
.t-cell__title-text {
  font-size: 14px;
}
.t-form__label--left {
  font-size: 14px; /* 调整左侧标签字体大小 */
}

.t-form__label {
  padding: 0;
}

.t-input--default {
  font-size: 13px;
}

.t-input--default::placeholder {
  color: gray; /* 设置颜色 */
  font-size: 14px !important; /* 设置字体大小 */
  border: none;
  /* 其他样式，例如字体系列 */
}

.t-form__item {
  padding-left: 10px;
  padding-right: 10px;
}

.t-input--default {
  font-size: 14px; /* 调整输入框字体大小 */
  border-bottom: none !important; /* 移除默认下划线 */
}
.t_cell {
  color: #000;
  font-size: 12px;
}
.t-cell__note {
  font-size: 14px;
}
.proptitle {
  font-size: 16px;
  font-weight: 600;
  padding: 10px 0;
}
.form-content {
  min-height: 0 !important;
  max-height: 70vh;
  overflow-y: auto;
}
</style>